package com.mew.slots.core.game.mnyys.service;

import com.alibaba.fastjson.JSON;
import com.mew.common.enm.SlotsWinType;
import com.mew.common.entity.game.WinFree;
import com.mew.slots.core.common.game.BaseGameService;
import com.mew.slots.core.common.game.vo.BasePlayMsgs;
import com.mew.slots.core.common.messge.response.SlotsPlayResponseMessage;
import com.mew.slots.core.common.vo.StrategyGameVO;
import com.mew.slots.core.game.mnyys.dto.MnyysInRoom;
import com.mew.slots.core.game.mnyys.dto.MnyysPlayMsgs;
import com.mew.slots.core.game.mnyys.message.MnyysPlayResponseMessage;
import com.mew.slots.core.game.mnyys.roller.MnyysXml;
import com.mew.slots.core.game.mnyys.room.MnyysRoom;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @author dylin
 */
@Service
public class MnyysService extends BaseGameService {
    @Override
    public BasePlayMsgs startGame(StrategyGameVO player) {
        WinFree winFree=player.getWinFree();
        MnyysInRoom vo;
        if (StringUtils.isNotEmpty(winFree.getJson())){
            vo = JSON.parseObject(winFree.getJson(),MnyysInRoom.class);
        }else{
            vo = new MnyysInRoom();
        }
        MnyysRoom room = new MnyysRoom(vo);
        room.init(player.getRollerId(), MnyysXml.getInstance(),player.getWinType()==SlotsWinType.Free.code(),player.getInBetNumber(),player.getControlType());
        room.roundPlay();
        winFree.setJson(JSON.toJSONString(vo));
        return room.getRes();
    }

    @Override
    public SlotsPlayResponseMessage myResp(WinFree winFree, BasePlayMsgs res) {
        MnyysPlayResponseMessage message = new MnyysPlayResponseMessage();
        MnyysPlayMsgs pmres=(MnyysPlayMsgs) res;
        if(pmres.getBouns()>0){
            message.setBonus(pmres.getBouns());
            winFree.setBounsNumber(pmres.getBouns());
        }
        message.setProgressBar(pmres.getProgressBar());
        message.setGoldenFrees(pmres.getGoldenFrees());
        return message;
    }

    @Override
    public void myAfterResp(SlotsPlayResponseMessage message,StrategyGameVO player, BasePlayMsgs res) {}

}
